package com.softserve.academy.food.services;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.softserve.academy.food.controllers.datamodel.ModelHistorydata;
import com.softserve.academy.food.dao.HibernateHistoryOrder;
import com.softserve.academy.food.dao.HibernateUser;
import com.softserve.academy.food.entity.eHistoryOrders;

@Service
public class HistoryOrder implements iHistoryOrder 
{
	@Autowired
	private HibernateUser daoUser;
	@Autowired
	private HibernateHistoryOrder daoHistoryOrder;

	@Override
	@Transactional
	public ArrayList<ModelHistorydata> getHistory( String login )
	{
		ArrayList<ModelHistorydata> historyList = new ArrayList<ModelHistorydata>(); 
		ArrayList<eHistoryOrders> list = daoHistoryOrder.getUser( daoUser.getUser(login) );

		if ( list!=null )
		{
			for ( eHistoryOrders eHistory : list )
			{
				historyList.add( new ModelHistorydata(eHistory) );
			}
		}
		
		return historyList;
	}

}
